home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / dev / gui / textfield.lha / Textfield / MUITest / TextFieldAuto.c < prev    next >
C/C++ Source or Header  |  1995-06-23  |  2KB  |  91 lines

  1. /*
  2.  * TextField autoinit and autoterminate functions
  3.  * for SAS/C 6.50 and up.
  4.  *
  5.  * If you just compile and link this into your application
  6.  * then TextFieldBase and TextFieldClass will be
  7.  * automatically initialized before main() is called.
  8.  *
  9.  * Your application will only need to use TextFieldClass
  10.  * when calling NewObject() and include <proto/textfield.h>.
  11.  *
  12.  * This file uses the TEXTFIELD_NAME and TEXTFIELD_VER
  13.  * defines from textfield.h.
  14.  *
  15.  * If the library fails to open, a warning is printed.
  16.  */
  17.  
  18. #include <string.h>
  19.  
  20. #include <gadgets/textfield.h>
  21.  
  22. #include <proto/dos.h>
  23. #include <proto/exec.h>
  24. #include <proto/textfield.h>
  25.  
  26. static void __regargs __tfopenfail(char *);
  27.  
  28. extern struct WBStartup *_WBenchMsg;
  29. extern char __stdiowin[];
  30.  
  31. struct Library *TextFieldBase;
  32. Class *TextFieldClass;
  33.  
  34. int _STI_200_TextFieldInit(void)
  35. {
  36.     TextFieldBase = OpenLibrary(TEXTFIELD_NAME, TEXTFIELD_VER);
  37.     if (TextFieldBase == NULL)
  38.     {
  39.         __tfopenfail("textfield.gadget");
  40.         return 1;
  41.     }
  42.     else
  43.     {
  44.         TextFieldClass = TEXTFIELD_GetClass();
  45.         return 0;
  46.     }
  47. }
  48.  
  49. void _STD_200_TextFieldTerm(void)
  50. {
  51.     CloseLibrary(TextFieldBase);
  52.     TextFieldClass = NULL;
  53.     TextFieldBase = NULL;
  54. }
  55.  
  56. // Modified from SAS/C's __autoopenfail()
  57.  
  58. static void __regargs __tfopenfail(char *lib)
  59. {
  60.     struct DOSBase *DOSBase;
  61.     long fh;
  62.    
  63.     DOSBase = (struct DOSBase *)OpenLibrary("dos.library", 0);
  64.     if (_WBenchMsg == NULL)
  65.         fh = Output();
  66.     else
  67.         fh = Open(__stdiowin, MODE_NEWFILE);
  68.  
  69.     if (fh)
  70.     {
  71.         char buf[50];
  72.         unsigned long libversion = TEXTFIELD_VER;
  73.         RawDoFmt("Can't open version %ld of ",
  74.             &libversion, (void (*))"\x16\xC0\x4E\x75", buf);
  75.    
  76.         Write(fh, buf, strlen(buf));
  77.         Write(fh, lib, strlen(lib));
  78.         Write(fh, ".\n", 2);
  79.    
  80.         if (_WBenchMsg)
  81.         {
  82.             Delay(200);
  83.             Close(fh);
  84.         }
  85.     }   
  86.  
  87.     CloseLibrary((struct Library *)DOSBase);
  88.     ((struct Process *)FindTask(NULL))->pr_Result2 = 
  89.                 ERROR_INVALID_RESIDENT_LIBRARY;
  90. }
  91.